package com.zdc.broad.pens;

import android.graphics.Canvas;
import android.text.TextPaint;
import android.text.TextUtils;

import com.zdc.broad.comm.CommHandwriting;

public class TextWriter implements CommHandwriting {

    float x, y;
    String text;
    TextPaint mPenPaint;

    public TextWriter(TextEvent listener, int penSize, int penColor) {
        this.listener = listener;
        initPaint(penSize, penColor);
    }

    protected void initPaint(int penSize, int penColor) {
        mPenPaint = new TextPaint();
        mPenPaint.setColor(penColor);
        mPenPaint.setTextSize(Math.max(penSize, 25));
        mPenPaint.setAntiAlias(true);
    }

    @Override
    public void draw(Canvas canvas) {
        if (!TextUtils.isEmpty(text)) {
            draw(canvas, text);
        }
    }

    public void draw(Canvas canvas, String text) {
        this.text = text;
        canvas.drawText(text, x, y, mPenPaint);
    }

    @Override
    public void touchDown(float x, float y) {

    }

    @Override
    public void touchMove(float x, float y) {

    }

    @Override
    public void touchUp(float x, float y) {
        this.x = x;
        this.y = y;
        if (listener != null) {
            listener.inputText(this);
        }
    }

    @Override
    public boolean hasDraw() {
        return false;
    }

    TextEvent listener;

    public interface TextEvent {
        void inputText(TextWriter writer);
    }
}
